import logging.config
import sys

import redis
import yaml
from elasticsearch import Elasticsearch
from flask import Flask
from flask_cors import CORS
from flask_restful import Api

from api import engine
from api import wechat, brand, jd, classcloud, weibo, daren, monitor, wetao
from api.api import ElasticSearchQueryResource

from changer.jd.price_modify import JDPriceModifyChanger

from querier.article_search.article_info import ArticleInfoQuerier
from querier.article_search.article_search import ArticleSearchQuerier
from querier.article_search.get_article import ArticleHBASEQuerier
from querier.article_search.originality_check import ArticleOriginalityCheckQuerier

from querier.brand.brand_wordcloud import BrandWordCloudQuerier
from querier.brand.brand_wordcloud_match import BrandWordCloudMatchResource

from querier.classcloud.class1_wordcloud import Class1WordCloudQuerier
from querier.classcloud.class1_wordcloud_match import Class1WordCloudMatchQuerier
from querier.classcloud.class2_wordcloud import Class2WordCloudQuerier
from querier.classcloud.class2_wordcloud_match import Class2WordCloudMatchQuerier

from querier.daren.kol_match import DarenKOLMatchQuerier

from querier.echo.para_combine import ParaCombineQuerier
from querier.echo.paragraph_search import SearchParagraphQuerier
from querier.echo.paragraph_search_text import SearchParagraphTextQuerier

from querier.engine import InfoQuerier

from querier.jd_shop.jd_goodswordcloud import JDGoodsWordCloudQuerier
from querier.jd_shop.jd_shop_goods import JDShopGoodsQuerier
from querier.jd_shop.jd_shop_goods_all import JDShopGoodsMatchAllQuerier
from querier.jd_shop.jd_shop_match import JDShopMatchQuerier
from querier.jd_shop.jd_shopwordcloud import JDShopWordCloudQuerier

from querier.monitor.network_monitoring import NetworkMonitoring

from querier.wechat.article_info import WechatArticleInfoQuerier
from querier.wechat.article_recommend import WechatRecommendQuerier
from querier.wechat.brand_kol_match import WechatBrandKOLMatchQuerier
from querier.wechat.categories import WechatCategoriesQuerier
from querier.wechat.communicate_analysis import CommuAanlysisMultiQuerier, CommuAanlysisQuerier
from querier.wechat.content_analyze_all import WechatContentAnalyzeAllQuerier
from querier.wechat.content_type_tags import WechatContentTypeTagsQuerier
from querier.wechat.data_overview import WechatDataOverviewQuerier
from querier.wechat.deprecated.article_search import WechatArticleSearchQuerier
from querier.wechat.deprecated.article_search_mini import WechatArticleSearchMiniQuerier
from querier.wechat.deprecated.article_search_mx import WechatArticleSearchMXQuerier
from querier.wechat.deprecated.keywords_heat import WechatKeywordHeatQuerier, WechatMultiKeywordHeatQuerier
from querier.wechat.deprecated.kol_match_mini import WechatKOLMatchMiniQuerier
from querier.wechat.deprecated.kol_match_mx import WechatKOLMatchMXQuerier
from querier.wechat.hot_word_trend import HotWordTrendQuerier
from querier.wechat.kol_info import WechatKOLInfoQuerier
from querier.wechat.kol_info import WechatKOLInfoWithBrandQuerier
from querier.wechat.kol_match import WechatKOLMatchQuerier
from querier.wechat.kol_match import WechatKOLMatchWithBrandQuerier
from querier.wechat.popular_kol import PopularKolQuerier
from querier.wechat.pub_stat import WechatPubStatQuerier, WechatPubStatMultiQuerier
from querier.wechat.tags import WechatTagsQuerier
from querier.wechat.time_slot_analyze_all import WechatTimeSlotAnalyzeAllQuerier
from querier.wechat.title_clustering import WechatTitleClusteringQuerier
from querier.wechat.trend_analyze import WechatTrendAnalyzeQuerier
from querier.wechat.trend_influence import WechatTrendInfluenceQuerier
from querier.wechat.trend_influence_all import WechatTrendInfluenceAllQuerier
from querier.wechat.user_info_analysis import WechatUserInfoAnalysisQuerier
from querier.wechat.user_pub_stat import WechatUserPubStatMultiQuerier, WechatUserPubStatQuerier
from querier.wechat.w2v_search import WordDfInfoQuerier, Word2VecInfoQuerier, Word2VecSearchQuerier
from querier.wechat_backend.article_search_mx import WechatArticleSearchBackendQuerier
from querier.wechat_backend.keywords_cloud import KeywordCloudQuerier
from querier.wechat_backend.kol_match_mx import WechatKOLMatchBackendQuerier
from querier.wechat_backend.kol_words_search import WechatKOLSearchWords

from querier.weibo.brand_kol_match import WeiboBrandKOLMatchQuerier
from querier.weibo.categories import WeiboCategoriesQuerier
from querier.weibo.communicate_analysis import WeiboCommuAanlysisMultiQuerier, WeiboCommuAanlysisQuerier
from querier.weibo.content_analyze import WeiboContentAnalyzeAllQuerier
from querier.weibo.content_type_tags import WeiboContentTypeTagsQuerier
from querier.weibo.data_overview import WeiboDataOverviewQuerier
from querier.weibo.deprecated.kol_match_mini import WeiboKOLMatchMiniQuerier
from querier.weibo.deprecated.kol_match_mx import WeiboKOLMatchMXQuerier
from querier.weibo.engagement_info import WeiboUserEngagementQuerier
from querier.weibo.kol_info import WeiboKOLInfoQuerier
from querier.weibo.kol_info import WeiboKOLInfoWithBrandQuerier
from querier.weibo.kol_match import WeiboKOLMatchQuerier
from querier.weibo.popular_user import PopularUserQuerier
from querier.weibo.post_info import WeiboPostInfoQuerier
from querier.weibo.post_search import WeiboPostSearchQuerier
from querier.weibo.pub_stat import WeiboPubStatQuerier, WeiboPubStatMultiQuerier
from querier.weibo.tags import WeiboTagsQuerier
from querier.weibo.time_slot_analyze import WeiboTimeSlotAnalyzeAllQuerier, WeiboTimeSlotAnalyzeQuerier
from querier.weibo.topic_search import WeiboTopicSearchQuerier
from querier.weibo.trend_analyze import WeiboTrendAnalyzeQuerier
from querier.weibo.trend_influence import WeiboTrendInfluenceQuerier
from querier.weibo.trend_influence_all import WeiboTrendInfluenceAllQuerier
from querier.weibo.user_info_analysis import WeiboUserInfoAnalysisQuerier
from querier.weibo.user_pub_stat import WeiboUserPubStatMultiQuerier, WeiboUserPubStatQuerier

from querier.article_search.movie_articles import MovieQuerier
from querier.article_search.drama_articles import DramaQuerier
from querier.article_search.tv_show_articles import TVShowQuerier
from querier.article_search.star_articles import StarQuerier
from querier.article_search.get_movie_info import MovieInfoQuerier
from querier.article_search.get_star_info import StarInfoQuerier
from querier.article_search.get_drama_info import DramaInfoQuerier
from querier.article_search.get_tv_show_info import TVShowInfoQuerier

from querier.wetao.kol_info import WetaoKOLInfoQuerier
from querier.wetao.kol_match import WetaoKOLMatchQuerier

from utils.nlp_client import NLPService


def load_yaml(yaml_file):
    with open(yaml_file, 'r') as infile:
        configure = yaml.load(infile)
    return configure


def set_logging(config_file):
    configure = load_yaml(config_file)
    logging.config.dictConfig(configure)


# noinspection PyTypeChecker
def load_app(config_file, logging_config_file):
    app = Flask(__name__)
    api = Api(app)
    CORS(app)

    config = load_yaml(config_file)
    set_logging(logging_config_file)
    timeout = config['es_config']['timeout']
    hosts = config['es_config']['hosts']
    es = Elasticsearch(hosts, timeout=timeout)

    # redis_url = config['redis_config']['redis_url']
    # app.config['REDIS_URL'] = redis_url
    redis_store = redis.Redis(host='192.168.31.200', port=6379, db=0, password='Youka888')
    ElasticSearchQueryResource.set_resource(redis_store=redis_store)

    nlp_conf = config['nlp_client']
    defaults = {}
    if 'keyword_top_k' in nlp_conf:
        defaults['keyword_top_k'] = nlp_conf['keyword_top_k']
    if 'keyword_allow_pos' in nlp_conf:
        defaults['keyword_allow_pos'] = nlp_conf['keyword_allow_pos']
    if 'keyword_cloud_n' in nlp_conf:
        defaults['keyword_cloud_n'] = nlp_conf['keyword_cloud_n']

    brand_pickle = config['local_models']['flag_brands']['path']
    nlp_service = NLPService(nlp_conf['host'], nlp_conf['port'], nlp_conf['timeout'], defaults=defaults,
                             brand_pickle=brand_pickle)

    indices = config['indices']

    # get article
    article_hbase_querier = ArticleHBASEQuerier(config['hbase']['host'], config['hbase']['table'])
    wechat.ArticleHBASEResource.set_resource(wechat.article_info_parser,
                                             get_querier=article_hbase_querier,
                                             post_querier=article_hbase_querier)

    # 公用
    kol_index_list = [indices['articles'], indices['weibo_post']]
    engine_info_query = InfoQuerier(es, kol_index_list)
    engine.EngineInfoResource.set_resource(engine.empty_parser, get_querier=engine_info_query,
                                           post_querier=engine_info_query)

    # 搜索公众号
    wechat_kol_match_query = WechatKOLMatchQuerier(es, indices['wechat_kol']['index'],
                                                   indices['wechat_kol']['doc_type'],
                                                   nlp_service)
    wechat_brand_match = BrandWordCloudMatchResource(es, indices['wechat_brand']['index'],
                                                     indices['wechat_brand']['doc_type'])

    wechat_brand_info = BrandWordCloudQuerier(es, indices['wechat_brand']['index'],
                                              indices['wechat_brand']['doc_type'])

    # 简化搜索借口
    wechat_kol_match_mini_query = WechatKOLMatchMiniQuerier(es, indices['wechat_kol']['index'],
                                                            indices['wechat_kol']['doc_type'],
                                                            nlp_service)
    wechat.WechatKOLMatchMiniResource.set_resource(wechat.wechat_kol_match_parser,
                                                   get_querier=wechat_kol_match_mini_query,
                                                   post_querier=wechat_kol_match_mini_query)

    wechat_article_search_mini_query = WechatArticleSearchMiniQuerier(es, indices['articles']['index'],
                                                                      indices['articles']['doc_type'],
                                                                      nlp_service)
    wechat.WechatArticleSearchMiniResource.set_resource(wechat.wechat_article_match_parser,
                                                        get_querier=wechat_article_search_mini_query,
                                                        post_querier=wechat_article_search_mini_query)

    wechat_title_clustering_query = WechatTitleClusteringQuerier(wechat_article_search_mini_query, nlp_service)
    wechat.WechatTitleClusteringResource.set_resource(wechat.wechat_article_match_parser,
                                                      get_querier=wechat_title_clustering_query,
                                                      post_querier=wechat_title_clustering_query)

    # 智能匹配
    wechat_article_search_mx_query = WechatArticleSearchMXQuerier(es, indices['articles']['index'],
                                                                  indices['articles']['doc_type'],
                                                                  nlp_service)
    wechat.WechatArticleSearchMXResource.set_resource(wechat.wechat_article_search_mx_parser,
                                                      get_querier=wechat_article_search_mx_query,
                                                      post_querier=wechat_article_search_mx_query)

    wechat_kol_match_mx_query = WechatKOLMatchMXQuerier(es, indices['wechat_kol']['index'],
                                                        indices['wechat_kol']['doc_type'],
                                                        nlp_service)
    wechat.WechatKOLMatchMXResource.set_resource(wechat.wechat_kol_match_mx_parser,
                                                 get_querier=wechat_kol_match_mx_query,
                                                 post_querier=wechat_kol_match_mx_query)

    wechat_pub_stat_query = WechatPubStatQuerier(es, indices['articles']['index'],
                                                 indices['articles']['doc_type'])
    wechat.WechatPubStatResource.set_resource(wechat.pub_stat_parser,
                                              get_querier=wechat_pub_stat_query,
                                              post_querier=wechat_pub_stat_query)

    wechat_pub_stat_multi_query = WechatPubStatMultiQuerier(wechat_pub_stat_query)
    wechat.WechatPubStatMultiResource.set_resource(wechat.pub_stat_parser,
                                                   get_querier=wechat_pub_stat_multi_query,
                                                   post_querier=wechat_pub_stat_multi_query)

    # 舆情监控
    hot_word_trend_query = HotWordTrendQuerier(wechat_pub_stat_multi_query, nlp_service)
    wechat.HotWordTrendResource.set_resource(wechat.pub_stat_parser, get_querier=hot_word_trend_query,
                                             post_querier=hot_word_trend_query)

    wechat_user_pub_stat_query = WechatUserPubStatQuerier(es, indices['articles']['index'],
                                                          indices['articles']['doc_type'])

    wechat_user_pub_stat_multi_query = WechatUserPubStatMultiQuerier(wechat_user_pub_stat_query)
    wechat.WechatUserPubStatMultiResource.set_resource(wechat.pub_stat_parser,
                                                       get_querier=wechat_user_pub_stat_multi_query,
                                                       post_querier=wechat_user_pub_stat_multi_query)

    commu_analysis_query = CommuAanlysisQuerier(es, indices['articles']['index'],
                                                indices['articles']['doc_type'])

    commu_analysis_multi_query = CommuAanlysisMultiQuerier(commu_analysis_query)
    wechat.CommunicationAnalysisMultiResource.set_resource(wechat.pub_stat_parser,
                                                           get_querier=commu_analysis_multi_query,
                                                           post_querier=commu_analysis_multi_query)

    wechat_user_info_analysis_query = WechatUserInfoAnalysisQuerier(es, indices['wechat_user_info_index']['index'],
                                                                    indices['wechat_user_info_index']['doc_type'])

    wechat.WechatUserInfoAnalysisResource.set_resource(wechat.pub_stat_parser,
                                                       get_querier=wechat_user_info_analysis_query,
                                                       post_querier=wechat_user_info_analysis_query)
    ########################################################################################
    wechat_word_info_query = WordDfInfoQuerier(es, indices['wechat_word_df']['index'],
                                               indices['wechat_word_df']['doc_type'])
    wechat_word2vec_info_title_query = Word2VecInfoQuerier(es, indices['wechat_word2vec_title']['index'],
                                                           indices['wechat_word2vec_title']['doc_type'])

    wechat_word2vec_info_text_query = Word2VecInfoQuerier(es, indices['wechat_word2vec_text']['index'],
                                                          indices['wechat_word2vec_text']['doc_type'])

    wechat_word2vec_search_title_query = Word2VecSearchQuerier(wechat_word2vec_info_title_query, wechat_word_info_query)
    wechat_word2vec_search_text_query = Word2VecSearchQuerier(wechat_word2vec_info_text_query, wechat_word_info_query)
    wechat.WechatWord2VecTitleSearchResource.set_resource(wechat.word2vec_parser,
                                                          get_querier=wechat_word2vec_search_title_query,
                                                          post_querier=wechat_word2vec_search_title_query)

    wechat.WechatWord2VecTextSearchResource.set_resource(wechat.word2vec_parser,
                                                         get_querier=wechat_word2vec_search_text_query,
                                                         post_querier=wechat_word2vec_search_text_query)

    wechat_assoc_info_title_query = Word2VecInfoQuerier(es, indices['wechat_assoc_title']['index'],
                                                        indices['wechat_assoc_title']['doc_type'])

    wechat_assoc_info_text_query = Word2VecInfoQuerier(es, indices['wechat_assoc_text']['index'],
                                                       indices['wechat_assoc_text']['doc_type'])

    wechat_assoc_search_title_query = Word2VecSearchQuerier(wechat_assoc_info_title_query, wechat_word_info_query)
    wechat_assoc_search_text_query = Word2VecSearchQuerier(wechat_assoc_info_text_query, wechat_word_info_query)
    wechat.WechatWordAssocTitleSearchResource.set_resource(wechat.word2vec_parser,
                                                           get_querier=wechat_assoc_search_title_query,
                                                           post_querier=wechat_assoc_search_title_query)

    wechat.WechatWordAssocTextSearchResource.set_resource(wechat.word2vec_parser,
                                                          post_querier=wechat_assoc_search_text_query)

    # 获取品牌
    wechat_kol_match_with_brand_query = WechatKOLMatchWithBrandQuerier(wechat_kol_match_query, wechat_brand_match)
    wechat.WechatKOLMatchResource.set_resource(wechat.wechat_kol_match_parser,
                                               get_querier=wechat_kol_match_with_brand_query,
                                               post_querier=wechat_kol_match_with_brand_query)

    wechat_brand_kol_match_query = WechatBrandKOLMatchQuerier(wechat_kol_match_with_brand_query, wechat_brand_info)
    wechat.WechatBrandKOLMatchResource.set_resource(wechat.wechat_kol_match_parser,
                                                    get_querier=wechat_brand_kol_match_query,
                                                    post_querier=wechat_brand_kol_match_query)

    # 获取公众号信息
    wechat_kol_info_query = WechatKOLInfoQuerier(es, indices['wechat_kol']['index'], indices['wechat_kol']['doc_type'],
                                                 nlp_service)

    wechat_kol_info_with_brand_query = WechatKOLInfoWithBrandQuerier(wechat_kol_info_query, wechat_brand_match)
    wechat.WechatKOLInfoResource.set_resource(wechat.wechat_kol_match_parser,
                                              get_querier=wechat_kol_info_with_brand_query,
                                              post_querier=wechat_kol_info_with_brand_query)

    popular_kol_query = PopularKolQuerier(commu_analysis_multi_query,
                                          wechat_kol_info_query)
    wechat.PopularKolResource.set_resource(wechat.pub_stat_parser,
                                           get_querier=popular_kol_query,
                                           post_querier=popular_kol_query)

    # 通过url获取公众号文章信息
    wechat_article_info_query = WechatArticleInfoQuerier(es, indices['articles']['index'],
                                                         indices['articles']['doc_type'], nlp_service)
    wechat.WechatArticleInfoResource.set_resource(wechat.wechat_article_info_parser,
                                                  get_querier=wechat_article_info_query,
                                                  post_querier=wechat_article_info_query)

    wechat_article_search_query = WechatArticleSearchQuerier(es, indices['articles']['index'],
                                                             indices['articles']['doc_type'], nlp_service)
    wechat.WechatArticleSearchResource.set_resource(wechat.wechat_article_match_parser,
                                                    get_querier=wechat_article_search_query,
                                                    post_querier=wechat_article_search_query)

    # 公众号所属类别
    wechat_categories_query = WechatCategoriesQuerier(es, indices['wechat_kol']['index'],
                                                      indices['wechat_kol']['doc_type'])
    wechat.WechatCategoriesResource.set_resource(wechat.wechat_article_match_parser,
                                                 get_querier=wechat_categories_query,
                                                 post_querier=wechat_categories_query)

    wechat_tags_query = WechatTagsQuerier(es, indices['wechat_kol']['index'], indices['wechat_kol']['doc_type'])
    wechat.WechatTagsResource.set_resource(wechat.wechat_kol_match_parser,
                                           get_querier=wechat_tags_query,
                                           post_querier=wechat_tags_query)

    wechat_content_type_tags_query = WechatContentTypeTagsQuerier(es, indices['wechat_kol']['index'],
                                                                  indices['wechat_kol']['doc_type'])
    wechat.WechatContentTypeTagsResource.set_resource(wechat.wechat_kol_match_parser,
                                                      get_querier=wechat_content_type_tags_query,
                                                      post_querier=wechat_content_type_tags_query)

    # 公众号详情概览
    wechat_data_overview_query = WechatDataOverviewQuerier(es, indices['wechat_click']['index'],
                                                           indices['wechat_click']['doc_type'])
    wechat.WechatDataOverviewResource.set_resource(wechat.wechat_data_analyze_parser,
                                                   get_querier=wechat_data_overview_query,
                                                   post_querier=wechat_data_overview_query)

    # 趋势分析
    wechat_trend_analyze_query = WechatTrendAnalyzeQuerier(es, indices['wechat_click']['index'],
                                                           indices['wechat_click']['doc_type'])
    wechat_influence_trend_query = WechatTrendInfluenceQuerier(es, indices['wechat_influence']['index'],
                                                               indices['wechat_influence']['doc_type'])

    wechat_trend_influence_all_query = WechatTrendInfluenceAllQuerier(wechat_trend_analyze_query,
                                                                      wechat_influence_trend_query)
    wechat.WechatTrendInfluenceAllResource.set_resource(wechat.wechat_data_analyze_parser,
                                                        get_querier=wechat_trend_influence_all_query,
                                                        post_querier=wechat_trend_influence_all_query)

    # 时段分析
    wechat_time_slot_analyze_all_query = WechatTimeSlotAnalyzeAllQuerier(es, indices['wechat_click']['index'],
                                                                         indices['wechat_click']['doc_type'])
    wechat.WechatTimeSlotAnalyzeAllResource.set_resource(wechat.wechat_data_analyze_parser,
                                                         get_querier=wechat_time_slot_analyze_all_query,
                                                         post_querier=wechat_time_slot_analyze_all_query)

    # 内容分析
    wechat_content_analyze_all_query = WechatContentAnalyzeAllQuerier(es, indices['wechat_click']['index'],
                                                                      indices['wechat_click']['doc_type'])
    wechat.WechatContentAnalyzeAllResource.set_resource(wechat.wechat_data_analyze_parser,
                                                        get_querier=wechat_content_analyze_all_query,
                                                        post_querier=wechat_content_analyze_all_query)

    # 搜索词热度分析
    wechat_keyword_heat_query = WechatKeywordHeatQuerier(es, indices['articles']['index'],
                                                         indices['articles']['doc_type'])
    wechat.WechatKeywordHeatResource.set_resource(wechat.wechat_data_analyze_parser,
                                                  get_querier=wechat_keyword_heat_query,
                                                  post_querier=wechat_keyword_heat_query)

    wechat_multi_keyword_heat_query = WechatMultiKeywordHeatQuerier(es, indices['articles']['index'],
                                                                    indices['articles']['doc_type'])
    wechat.WechatMultiKeywordHeatResource.set_resource(wechat.wechat_data_analyze_parser,
                                                       get_querier=wechat_multi_keyword_heat_query,
                                                       post_querier=wechat_multi_keyword_heat_query)

    # 后台模糊匹配
    wechat_kol_search_words_query = WechatKOLSearchWords(es, indices['wechat_kol']['index'],
                                                         indices['wechat_kol']['doc_type'],
                                                         nlp_service)
    wechat.WechatKOLSearchWordsResource.set_resource(wechat.wechat_kol_match_parser,
                                                     get_querier=wechat_kol_search_words_query,
                                                     post_querier=wechat_kol_search_words_query)

    wechat_kol_match_backend_query = WechatKOLMatchBackendQuerier(es, indices['wechat_kol']['index'],
                                                                  indices['wechat_kol']['doc_type'],
                                                                  nlp_service)
    wechat.WechatKOLMatchBackendResource.set_resource(wechat.wechat_kol_match_mx_parser,
                                                      get_querier=wechat_kol_match_backend_query,
                                                      post_querier=wechat_kol_match_backend_query)
    wechat_article_search_backend_query = WechatArticleSearchBackendQuerier(es, indices['articles']['index'],
                                                                            indices['articles']['doc_type'],
                                                                            nlp_service)
    wechat.WechatArticleSearchBackendResource.set_resource(wechat.wechat_article_search_mx_parser,
                                                           get_querier=wechat_article_search_backend_query,
                                                           post_querier=wechat_article_search_backend_query)

    wechat_keyword_cloud_sim_query = KeywordCloudQuerier(wechat_word2vec_search_text_query, nlp_service)
    wechat_keyword_cloud_assoc_query = KeywordCloudQuerier(wechat_assoc_search_text_query, nlp_service)

    wechat.WechatKeywordCloudSimResource.set_resource(wechat.word2vec_parser,
                                                      get_querier=wechat_keyword_cloud_sim_query,
                                                      post_querier=wechat_keyword_cloud_sim_query)
    wechat.WechatKeywordCloudAssocResource.set_resource(wechat.word2vec_parser,
                                                        get_querier=wechat_keyword_cloud_assoc_query,
                                                        post_querier=wechat_keyword_cloud_assoc_query)

    # 文章推荐
    wechat_article_recommend_querier = WechatRecommendQuerier(es, indices['articles']['index'],
                                                              indices['articles']['doc_type'],
                                                              indices['wechat_article_recommend']['index'],
                                                              indices['wechat_article_recommend']['doc_type'],
                                                              nlp_service)
    wechat.WechatRecommendResource.set_resource(wechat.wechat_article_recommend_parser,
                                                get_querier=wechat_article_recommend_querier,
                                                post_querier=wechat_article_recommend_querier)

    article_search_querier = ArticleSearchQuerier(es, indices['articles']['index'],
                                                  indices['articles']['doc_type'],
                                                  nlp_service)
    wechat.ArticleSearchResource.set_resource(wechat.article_search_parser,
                                              get_querier=article_search_querier,
                                              post_querier=article_search_querier)

    article_orig_check_querier = ArticleOriginalityCheckQuerier(article_search_querier)
    wechat.ArticleOriginalityCheckResource.set_resource(wechat.article_originality_check_parser,
                                                        get_querier=article_orig_check_querier,
                                                        post_querier=article_orig_check_querier)

    article_info_querier = ArticleInfoQuerier(es, indices['articles']['index'],
                                              indices['articles']['doc_type'],
                                              nlp_service)
    wechat.ArticleInfoResource.set_resource(wechat.article_info_parser,
                                            get_querier=article_info_querier,
                                            post_querier=article_info_querier)

    # 搜索微博

    weibo_kol_engagement_query = WeiboUserEngagementQuerier(es, indices['weibo_user_engagement']['index'],
                                                            indices['weibo_user_engagement']['doc_type'],
                                                            nlp_service)

    weibo_kol_match_query = WeiboKOLMatchQuerier(es, indices['weibo_kol']['index'], indices['weibo_kol']['doc_type'],
                                                 nlp_service, weibo_kol_engagement_query)
    weibo.WeiboKOLMatchResource.set_resource(weibo.weibo_kol_match_parser,
                                             get_querier=weibo_kol_match_query,
                                             post_querier=weibo_kol_match_query)

    # 使用brand搜索微博
    weibo_brand_kol_match_query = WeiboBrandKOLMatchQuerier(weibo_kol_match_query, wechat_brand_info)
    weibo.WeiboBrandKOLMatchResource.set_resource(weibo.weibo_kol_match_parser,
                                                  get_querier=weibo_brand_kol_match_query,
                                                  post_querier=weibo_brand_kol_match_query)

    # 获取微博用户信息
    weibo_kol_info_query = WeiboKOLInfoQuerier(es, indices['weibo_kol']['index'], indices['weibo_kol']['doc_type'])
    weibo_kol_brand_info_query = WeiboKOLInfoWithBrandQuerier(weibo_kol_info_query, wechat_brand_match)
    weibo.WeiboKOLInfoResource.set_resource(weibo.weibo_kol_match_parser,
                                            get_querier=weibo_kol_brand_info_query,
                                            post_querier=weibo_kol_brand_info_query)

    # 搜索微博文章
    weibo_post_search_query = WeiboPostSearchQuerier(es, indices['weibo_post']['index'],
                                                     indices['weibo_post']['doc_type'], nlp_service)
    weibo.WeiboPostSearchResource.set_resource(weibo.weibo_post_match_parser,
                                               get_querier=weibo_post_search_query,
                                               post_querier=weibo_post_search_query)

    # 微博搜索 精确搜索， 智能匹配
    # weibo_post_search_mini_query = WeiboPostSearchMiniQuerier(es, indices['weibo_post']['index'],
    #                                                           indices['weibo_post']['doc_type'], nlp_service)
    weibo.WeiboPostSearchMiniResource.set_resource(weibo.weibo_post_match_mini_parser,
                                                   get_querier=weibo_post_search_query,
                                                   post_querier=weibo_post_search_query)

    # weibo_post_search_mx_query = WeiboPostSearchMXQuerier(es, indices['weibo_post']['index'],
    #                                                       indices['weibo_post']['doc_type'], nlp_service)
    weibo.WeiboPostSearchMXResource.set_resource(weibo.weibo_post_match_mx_parser,
                                                 get_querier=weibo_post_search_query,
                                                 post_querier=weibo_post_search_query)

    weibo_kol_match_mini_query = WeiboKOLMatchMiniQuerier(es, indices['weibo_kol']['index'],
                                                          indices['weibo_kol']['doc_type'],
                                                          nlp_service)
    weibo.WeiboKOLMatchMiniResource.set_resource(weibo.weibo_kol_match_mini_parser,
                                                 get_querier=weibo_kol_match_mini_query,
                                                 post_querier=weibo_kol_match_mini_query)

    weibo_kol_match_mx_query = WeiboKOLMatchMXQuerier(es, indices['weibo_kol']['index'],
                                                      indices['weibo_kol']['doc_type'],
                                                      nlp_service)
    weibo.WeiboKOLMatchMXResource.set_resource(weibo.weibo_kol_match_mx_parser,
                                               get_querier=weibo_kol_match_mx_query,
                                               post_querier=weibo_kol_match_mx_query)

    weibo_post_info_query = WeiboPostInfoQuerier(es, indices['weibo_post']['index'],
                                                 indices['weibo_post']['doc_type'], nlp_service)
    weibo.WeiboPostInfoResource.set_resource(weibo.weibo_post_info_parser,
                                             get_querier=weibo_post_info_query,
                                             post_querier=weibo_post_info_query)

    weibo_pub_stat_query = WeiboPubStatQuerier(es, indices['weibo_post']['index'],
                                               indices['weibo_post']['doc_type'])

    weibo_pub_stat_multi_query = WeiboPubStatMultiQuerier(weibo_pub_stat_query)
    weibo.WeiboPubStatMultiResource.set_resource(weibo.pub_stat_parser,
                                                 get_querier=weibo_pub_stat_multi_query,
                                                 post_querier=weibo_pub_stat_multi_query)

    weibo_user_pub_stat_query = WeiboUserPubStatQuerier(es, indices['weibo_post']['index'],
                                                        indices['weibo_post']['doc_type'])

    weibo_user_pub_stat_multi_query = WeiboUserPubStatMultiQuerier(weibo_user_pub_stat_query)
    weibo.WeiboUserPubStatMultiResource.set_resource(weibo.pub_stat_parser,
                                                     get_querier=weibo_user_pub_stat_multi_query,
                                                     post_querier=weibo_user_pub_stat_multi_query)

    weibo_user_info_analysis_query = WeiboUserInfoAnalysisQuerier(es, indices['weibo_user_info_index']['index'],
                                                                  indices['weibo_user_info_index']['doc_type'])

    weibo.WeiboUserInfoAnalysisResource.set_resource(weibo.pub_stat_parser,
                                                     get_querier=weibo_user_info_analysis_query,
                                                     post_querier=weibo_user_info_analysis_query)

    weibo_commu_analysis_query = WeiboCommuAanlysisQuerier(es, indices['weibo_post']['index'],
                                                           indices['weibo_post']['doc_type'])

    weibo_commu_analysis_multi_query = WeiboCommuAanlysisMultiQuerier(weibo_commu_analysis_query)
    weibo.WeiboCommuAanlysisMultiResource.set_resource(weibo.pub_stat_parser,
                                                       get_querier=weibo_commu_analysis_multi_query,
                                                       post_querier=weibo_commu_analysis_multi_query)

    # 微博用户所属类别
    weibo_categories_query = WeiboCategoriesQuerier(es, indices['weibo_kol']['index'], indices['weibo_kol']['doc_type'])
    weibo.WeiboCategoriesResource.set_resource(weibo.weibo_post_match_parser,
                                               get_querier=weibo_categories_query,
                                               post_querier=weibo_categories_query)

    # 微博用户词云
    weibo_tags_query = WeiboTagsQuerier(es, indices['weibo_kol']['index'], indices['weibo_kol']['doc_type'])
    weibo.WeiboTagsResource.set_resource(weibo.weibo_kol_match_parser,
                                         get_querier=weibo_tags_query,
                                         post_querier=weibo_tags_query)

    weibo_content_type_tags_query = WeiboContentTypeTagsQuerier(es, indices['weibo_kol']['index'],
                                                                indices['weibo_kol']['doc_type'])
    weibo.WeiboContentTypeTagsResource.set_resource(weibo.weibo_kol_match_parser,
                                                    get_querier=weibo_content_type_tags_query,
                                                    post_querier=weibo_content_type_tags_query)

    # 微博用户详情概览
    weibo_data_overview_query = WeiboDataOverviewQuerier(es, indices['weibo_post']['index'],
                                                         indices['weibo_post']['doc_type'])
    weibo.WeiboDataOverviewResource.set_resource(weibo.weibo_data_analyze_parser,
                                                 get_querier=weibo_data_overview_query,
                                                 post_querier=weibo_data_overview_query)

    # 趋势分析
    weibo_trend_analyze_query = WeiboTrendAnalyzeQuerier(es, indices['weibo_post']['index'],
                                                         indices['weibo_post']['doc_type'])
    weibo_influence_trend_query = WeiboTrendInfluenceQuerier(es, indices['weibo_influence']['index'],
                                                             indices['weibo_influence']['doc_type'])

    weibo_trend_influence_all_query = WeiboTrendInfluenceAllQuerier(weibo_trend_analyze_query,
                                                                    weibo_influence_trend_query)
    weibo.WeiboTrendInfluenceAllResource.set_resource(weibo.weibo_data_analyze_parser,
                                                      get_querier=weibo_trend_influence_all_query,
                                                      post_querier=weibo_trend_influence_all_query)

    # 时段分析
    weibo_time_slot_analyze_query = WeiboTimeSlotAnalyzeQuerier(es, indices['weibo_post']['index'],
                                                                indices['weibo_post']['doc_type'])

    weibo_time_slot_analyze_all_query = WeiboTimeSlotAnalyzeAllQuerier(weibo_time_slot_analyze_query)
    weibo.WeiboTimeSlotAnalyzeAllResource.set_resource(weibo.weibo_data_analyze_parser,
                                                       get_querier=weibo_time_slot_analyze_all_query,
                                                       post_querier=weibo_time_slot_analyze_all_query)

    # 内容分析
    weibo_content_analyze_all_query = WeiboContentAnalyzeAllQuerier(es, indices['weibo_post']['index'],
                                                                    indices['weibo_post']['doc_type'])
    weibo.WeiboContentAnalyzeAllResource.set_resource(weibo.weibo_data_analyze_parser,
                                                      get_querier=weibo_content_analyze_all_query,
                                                      post_querier=weibo_content_analyze_all_query)

    # 搜索微博话题
    weibo_topic_search_query = WeiboTopicSearchQuerier(es, indices['weibo_topic']['index'],
                                                       indices['weibo_topic']['doc_type'])

    weibo.WeiboTopicSearchResource.set_resource(weibo.weibo_topic_search_parser,
                                                get_querier=weibo_topic_search_query,
                                                post_querier=weibo_topic_search_query)
    # 舆情分析 热门账号
    weibo_popular_user_query = PopularUserQuerier(weibo_commu_analysis_multi_query, weibo_kol_brand_info_query)
    weibo.WeiboPopularUserResource.set_resource(weibo.pub_stat_parser, get_querier=weibo_popular_user_query,
                                                post_querier=weibo_popular_user_query)

    # 品牌词云brand查找
    brandwordcloud_query = BrandWordCloudQuerier(es, indices['wechat_brand']['index'],
                                                 indices['wechat_brand']['doc_type'])
    brand.BrandWordCloudResource.set_resource(brand.brand_match_parser,
                                              get_querier=brandwordcloud_query,
                                              post_querier=brandwordcloud_query)

    # 品牌词云非精确查找
    brandwordcloudmatch_query = BrandWordCloudMatchResource(es, indices['wechat_brand']['index'],
                                                            indices['wechat_brand']['doc_type'])
    brand.BrandWordCloudMatchResource.set_resource(brand.brand_match_parser,
                                                   get_querier=brandwordcloudmatch_query,
                                                   post_querier=brandwordcloudmatch_query)

    # 一级类目词云
    class1wordcloud_query = Class1WordCloudQuerier(es, indices['wechat_class1']['index'],
                                                   indices['wechat_class1']['doc_type'])
    classcloud.Class1WordCloudResource.set_resource(classcloud.class1_match_parser,
                                                    get_querier=class1wordcloud_query,
                                                    post_querier=class1wordcloud_query)

    # 一级类目词云非精确查找
    class1wordcloudmatch_query = Class1WordCloudMatchQuerier(es, indices['wechat_class1']['index'],
                                                             indices['wechat_class1']['doc_type'])
    classcloud.Class1WordCloudMatchResource.set_resource(classcloud.class1_match_parser,
                                                         get_querier=class1wordcloudmatch_query,
                                                         post_querier=class1wordcloudmatch_query)

    # 二级类目词云
    class2wordcloud_query = Class2WordCloudQuerier(es, indices['wechat_class2']['index'],
                                                   indices['wechat_class2']['doc_type'])
    classcloud.Class2WordCloudResource.set_resource(classcloud.class2_match_parser,
                                                    get_querier=class2wordcloud_query,
                                                    post_querier=class2wordcloud_query)

    # 二级类目词云非精确查找
    class2wordcloudmatch_query = Class2WordCloudMatchQuerier(es, indices['wechat_class2']['index'],
                                                             indices['wechat_class2']['doc_type'])
    classcloud.Class2WordCloudMatchResource.set_resource(classcloud.class2_match_parser,
                                                         get_querier=class2wordcloudmatch_query,
                                                         post_querier=class2wordcloudmatch_query)

    # 京东商品词云
    jdgoodswrodcloud_query = JDGoodsWordCloudQuerier(es, indices['jd_goods']['index'], indices['jd_goods']['doc_type'])
    jd.JDGoodsWordCloudResource.set_resource(jd.jd_goods_match_parser,
                                             get_querier=jdgoodswrodcloud_query,
                                             post_querier=jdgoodswrodcloud_query)

    # 京东店铺词云
    jdshopwrodcloud_query = JDShopWordCloudQuerier(es, indices['jd_shop']['index'], indices['jd_shop']['doc_type'])
    jd.JDShopWordCloudResource.set_resource(jd.jd_goods_match_parser,
                                            get_querier=jdshopwrodcloud_query,
                                            post_querier=jdshopwrodcloud_query)

    # 京东店铺商品
    jdshopgoods_query = JDShopGoodsQuerier(es, indices['jd_shop_goods']['index'], indices['jd_shop_goods']['doc_type'])
    jd.JDShopGoodsResource.set_resource(jd.jd_goods_match_parser,
                                        get_querier=jdshopgoods_query,
                                        post_querier=jdshopgoods_query)

    # 京东店铺match
    jdshopmatch_query = JDShopMatchQuerier(es, indices['jd_shop']['index'],
                                           indices['jd_shop']['doc_type'], nlp_service)
    jd.JDShopMatchResource.set_resource(jd.jd_goods_match_parser,
                                        get_querier=jdshopmatch_query,
                                        post_querier=jdshopmatch_query)

    jd_shop_goods_match_all_query = JDShopGoodsMatchAllQuerier(jdshopmatch_query,
                                                               jdshopgoods_query)
    jd.JDShopGoodsMatchAllResouce.set_resource(jd.jd_goods_match_parser,
                                               get_querier=jd_shop_goods_match_all_query,
                                               post_querier=jd_shop_goods_match_all_query)

    jd_goods_price_modify_query = JDPriceModifyChanger(es, indices['jd_goods']['index'],
                                                       indices['jd_goods']['doc_type'])
    jd.JDGoodPriceModifyResource.set_resource(jd.jd_goods_changer_parser,
                                              get_querier=jd_goods_price_modify_query,
                                              post_querier=jd_goods_price_modify_query)

    # rosetta echo
    wechat_search_para_query = SearchParagraphQuerier(es, indices['wechat_paragraph']['index'],
                                                      indices['wechat_paragraph']['doc_type'], nlp_service)
    wechat.WechatParaSearchResource.set_resource(wechat.wechat_para_search_parser,
                                                 get_querier=wechat_search_para_query,
                                                 post_querier=wechat_search_para_query)

    wechat_para_combine_query = ParaCombineQuerier(wechat_search_para_query)
    wechat.ParaCombineResource.set_resource(wechat.para_combine_parser,
                                            get_querier=wechat_para_combine_query,
                                            post_querier=wechat_para_combine_query)

    wechat_search_para_text_query = SearchParagraphTextQuerier(es, indices['wechat_paragraph_text']['index'],
                                                               indices['wechat_paragraph_text']['doc_type'],
                                                               nlp_service)
    wechat.WechatParaSearchTextResource.set_resource(wechat.wechat_para_search_parser,
                                                     get_querier=wechat_search_para_text_query,
                                                     post_querier=wechat_search_para_text_query)

    daren_kol_query = DarenKOLMatchQuerier(es, indices['daren_kol']['index'],
                                           indices['daren_kol']['doc_type'], nlp_service)

    daren.DarenKOLMatchResource.set_resource(daren.daren_kol_match_parser,
                                             get_querier=daren_kol_query,
                                             post_querier=daren_kol_query)

    network_monitoring = NetworkMonitoring(config)
    monitor.NetworkMonitoringResource.set_resource(monitor.network_match_parser, get_querier=network_monitoring,
                                                   post_querier=network_monitoring)

    # only hotter
    pg_config = config['pg_config']
    only_hotter_movie_article_querier = MovieQuerier(article_search_querier, pg_config)
    wechat.MovieArticleResource.set_resource(wechat.only_hotter_parser, get_querier=only_hotter_movie_article_querier,
                                             post_querier=only_hotter_movie_article_querier)

    only_hotter_drama_article_querier = DramaQuerier(article_search_querier, pg_config)
    wechat.DramaArticleResource.set_resource(wechat.only_hotter_parser, get_querier=only_hotter_drama_article_querier,
                                             post_querier=only_hotter_drama_article_querier)

    only_hotter_tv_show_article_querier = TVShowQuerier(article_search_querier, pg_config)
    wechat.TVShowArticleResource.set_resource(wechat.only_hotter_parser,
                                              get_querier=only_hotter_tv_show_article_querier,
                                              post_querier=only_hotter_tv_show_article_querier)

    only_hotter_star_article_querier = StarQuerier(article_search_querier, pg_config)
    wechat.StarArticleResource.set_resource(wechat.only_hotter_parser,
                                            get_querier=only_hotter_star_article_querier,
                                            post_querier=only_hotter_star_article_querier)

    only_hotter_movie_info_query = MovieInfoQuerier(article_search_querier, pg_config)
    wechat.MovieInfoResource.set_resource(wechat.only_hotter_parser,
                                          get_querier=only_hotter_movie_info_query,
                                          post_querier=only_hotter_movie_info_query
                                          )

    only_hotter_star_info_query = StarInfoQuerier(article_search_querier, pg_config)
    wechat.StarInfoResource.set_resource(wechat.only_hotter_parser,
                                         get_querier=only_hotter_star_info_query,
                                         post_querier=only_hotter_star_info_query
                                         )

    only_hotter_drama_info_querier = DramaInfoQuerier(article_search_querier, pg_config)
    wechat.DramaInfoResource.set_resource(wechat.only_hotter_parser,
                                          get_querier=only_hotter_drama_info_querier,
                                          post_querier=only_hotter_drama_info_querier)

    only_hotter_tv_show_info_querier = TVShowInfoQuerier(article_search_querier, pg_config)
    wechat.TVShowInfoResource.set_resource(wechat.only_hotter_parser,
                                           get_querier=only_hotter_tv_show_info_querier,
                                           post_querier=only_hotter_tv_show_info_querier)
    # wetao kol info
    wetao_kol_query = WetaoKOLInfoQuerier(es, indices['wetao_kol']['index'],
                                          indices['wetao_kol']['doc_type'])

    wetao.WetaoKOLInfoResource.set_resource(wetao.wetao_kol_match_parser,
                                            get_querier=wetao_kol_query,
                                            post_querier=wetao_kol_query)

    wetao_kol_match_query = WetaoKOLMatchQuerier(es, indices['wetao_kol']['index'],
                                                 indices['wetao_kol']['doc_type'],
                                                 nlp_service)

    wetao.WetaoKOLMatchResource.set_resource(wetao.wetao_kol_match_parser,
                                             get_querier=wetao_kol_match_query,
                                             post_querier=wetao_kol_match_query)

    # 绑定API
    endpoints = config['endpoints']
    api.add_resource(engine.EngineInfoResource, endpoints['engine_info'])

    api.add_resource(daren.DarenKOLMatchResource, endpoints['daren_kol_match'])
    api.add_resource(wechat.ArticleSearchResource, endpoints['article_search'])
    api.add_resource(wechat.ArticleInfoResource, endpoints['article_info'])
    api.add_resource(wechat.ArticleHBASEResource, endpoints['article_hbase'])
    api.add_resource(wechat.ParaCombineResource, endpoints['wechat_combine_para'])
    api.add_resource(wechat.WechatKOLMatchResource, endpoints['wechat_kol_match'])
    api.add_resource(wechat.WechatBrandKOLMatchResource, endpoints['wechat_brand_kol_match'])
    api.add_resource(wechat.WechatKOLInfoResource, endpoints['wechat_kol_info'])
    api.add_resource(wechat.WechatArticleInfoResource, endpoints['wechat_article_info'])
    api.add_resource(wechat.WechatArticleSearchResource, endpoints['wechat_article_search'])

    # 20170405 加入新API
    api.add_resource(wechat.WechatKOLMatchMiniResource, endpoints['wechat_kol_match_mini'])
    api.add_resource(wechat.WechatArticleSearchMiniResource, endpoints['wechat_article_search_mini'])
    api.add_resource(wechat.WechatPubStatResource, endpoints['wechat_pub_stat'])
    api.add_resource(wechat.WechatPubStatMultiResource, endpoints['wechat_pub_stat_multi'])
    api.add_resource(wechat.WechatUserPubStatMultiResource, endpoints['wechat_user_pub_stat_multi'])
    api.add_resource(wechat.CommunicationAnalysisMultiResource, endpoints['wechat_content_communicate'])
    api.add_resource(wechat.WechatUserInfoAnalysisResource, endpoints['wechat_user_info_analysis'])

    api.add_resource(wechat.WechatWordAssocTitleSearchResource, endpoints['wechat_title_assoc'])
    api.add_resource(wechat.WechatWordAssocTextSearchResource, endpoints['wechat_text_assoc'])
    api.add_resource(wechat.WechatWord2VecTitleSearchResource, endpoints['wechat_title_sim'])
    api.add_resource(wechat.WechatWord2VecTextSearchResource, endpoints['wechat_text_sim'])

    api.add_resource(wechat.WechatArticleSearchMXResource, endpoints['wechat_article_search_mx'])
    api.add_resource(wechat.WechatKOLMatchMXResource, endpoints['wechat_kol_match_mx'])

    api.add_resource(wechat.WechatTitleClusteringResource, endpoints['wechat_title_cluster'])

    # 后台API
    api.add_resource(wechat.WechatKeywordCloudAssocResource, endpoints['keyword_cloud_assoc'])
    api.add_resource(wechat.WechatKeywordCloudSimResource, endpoints['keyword_cloud_sim'])
    api.add_resource(wechat.WechatKOLMatchBackendResource, endpoints['wechat_kol_match_backend'])
    api.add_resource(wechat.WechatArticleSearchBackendResource, endpoints['wechat_article_search_backend'])
    api.add_resource(wechat.WechatTagsResource, endpoints['wechat_tags'])
    api.add_resource(wechat.WechatCategoriesResource, endpoints['wechat_categories'])

    api.add_resource(wechat.WechatContentTypeTagsResource, endpoints['wechat_content_type_tags'])

    api.add_resource(wechat.WechatDataOverviewResource, endpoints['wechat_data_overview'])
    api.add_resource(wechat.WechatTrendInfluenceAllResource, endpoints['wechat_trend_analyze'])
    api.add_resource(wechat.WechatTimeSlotAnalyzeAllResource, endpoints['wechat_time_slot_analyze'])
    api.add_resource(wechat.WechatContentAnalyzeAllResource, endpoints['wechat_content_analyze'])
    api.add_resource(wechat.WechatKeywordHeatResource, endpoints['wechat_keyword_heat'])
    api.add_resource(wechat.WechatMultiKeywordHeatResource, endpoints['wechat_multi_keyword_heat'])
    api.add_resource(wechat.WechatKOLSearchWordsResource, endpoints['wechat_kol_words_search'])
    api.add_resource(wechat.WechatRecommendResource, endpoints['wechat_article_recommend'])
    api.add_resource(wechat.PopularKolResource, endpoints['wechat_popular_kol'])
    api.add_resource(wechat.HotWordTrendResource, endpoints['hot_word_trend'])

    api.add_resource(weibo.WeiboKOLMatchResource, endpoints['weibo_kol_match'])
    api.add_resource(weibo.WeiboBrandKOLMatchResource, endpoints['weibo_brand_kol_match'])
    api.add_resource(weibo.WeiboKOLInfoResource, endpoints['weibo_kol_info'])

    api.add_resource(weibo.WeiboPostSearchResource, endpoints['weibo_post_search'])
    api.add_resource(weibo.WeiboTagsResource, endpoints['weibo_tags'])
    api.add_resource(weibo.WeiboCategoriesResource, endpoints['weibo_categories'])
    api.add_resource(weibo.WeiboContentTypeTagsResource, endpoints['weibo_content_type_tags'])
    api.add_resource(weibo.WeiboDataOverviewResource, endpoints['weibo_data_overview'])
    api.add_resource(weibo.WeiboTrendInfluenceAllResource, endpoints['weibo_trend_analyze'])
    api.add_resource(weibo.WeiboTimeSlotAnalyzeAllResource, endpoints['weibo_time_slot_analyze'])
    api.add_resource(weibo.WeiboContentAnalyzeAllResource, endpoints['weibo_content_analyze'])
    api.add_resource(weibo.WeiboPostInfoResource, endpoints['weibo_post_info'])

    api.add_resource(weibo.WeiboKOLMatchMiniResource, endpoints['weibo_kol_match_mini'])
    api.add_resource(weibo.WeiboKOLMatchMXResource, endpoints['weibo_kol_match_mx'])
    api.add_resource(weibo.WeiboPostSearchMiniResource, endpoints['weibo_post_search_mini'])
    api.add_resource(weibo.WeiboPostSearchMXResource, endpoints['weibo_post_search_mx'])

    api.add_resource(weibo.WeiboTopicSearchResource, endpoints['weibo_topic_search'])

    api.add_resource(weibo.WeiboPubStatMultiResource, endpoints['weibo_pub_stat_multi'])
    api.add_resource(weibo.WeiboUserPubStatMultiResource, endpoints['weibo_user_stat'])
    api.add_resource(weibo.WeiboUserInfoAnalysisResource, endpoints['weibo_user_info_analysis'])
    api.add_resource(weibo.WeiboCommuAanlysisMultiResource, endpoints['weibo_content_communicate'])
    api.add_resource(weibo.WeiboPopularUserResource, endpoints['weibo_popular_user'])

    api.add_resource(brand.BrandWordCloudResource, endpoints['wechat_brands'])
    api.add_resource(brand.BrandWordCloudMatchResource, endpoints['wechat_brands_match'])

    api.add_resource(classcloud.Class1WordCloudResource, endpoints['wechat_class1'])
    api.add_resource(classcloud.Class1WordCloudMatchResource, endpoints['wechat_class1_match'])

    api.add_resource(classcloud.Class2WordCloudResource, endpoints['wechat_class2'])
    api.add_resource(classcloud.Class2WordCloudMatchResource, endpoints['wechat_class2_match'])

    api.add_resource(jd.JDGoodsWordCloudResource, endpoints['jd_goods'])
    api.add_resource(jd.JDShopWordCloudResource, endpoints['jd_shop'])
    api.add_resource(jd.JDShopGoodsResource, endpoints['jd_shop_goods'])
    api.add_resource(jd.JDShopMatchResource, endpoints['jd_shop_match'])
    api.add_resource(jd.JDShopGoodsMatchAllResouce, endpoints['jd_shop_goods_match_all'])
    api.add_resource(jd.JDGoodPriceModifyResource, endpoints['jd_shop_goods_price_modify'])

    api.add_resource(wechat.WechatParaSearchResource, endpoints['wechat_search_para'])
    api.add_resource(wechat.WechatParaSearchTextResource, endpoints['wechat_search_para_text'])
    api.add_resource(monitor.NetworkMonitoringResource, endpoints['network_monitoring'])
    # only hotter
    api.add_resource(wechat.MovieArticleResource, endpoints['only_hotter_movie_articles'])
    api.add_resource(wechat.DramaArticleResource, endpoints['only_hotter_drama_articles'])
    api.add_resource(wechat.TVShowArticleResource, endpoints['only_hotter_tv_show_articles'])
    api.add_resource(wechat.StarArticleResource, endpoints['only_hotter_star_articles'])
    api.add_resource(wechat.MovieInfoResource, endpoints['only_hotter_movie_info'])
    api.add_resource(wechat.StarInfoResource, endpoints['only_hotter_star_info'])
    api.add_resource(wechat.DramaInfoResource, endpoints['only_hotter_drama_info'])
    api.add_resource(wechat.TVShowInfoResource, endpoints['only_hotter_tv_show_info'])

    api.add_resource(wetao.WetaoKOLInfoResource, endpoints['wetao_kol_info'])
    api.add_resource(wetao.WetaoKOLMatchResource, endpoints['wetao_kol_match'])

    api.add_resource(wechat.ArticleOriginalityCheckResource, endpoints['article_originality_check'])
    return app


if __name__ == '__main__':
    if len(sys.argv) < 3:
        conf_file = ''
        logging_conf_file = ''
        print('Usage: python3.4 start_api.py <config.yaml> <logging.yaml>')
        exit(1)
    else:
        conf_file = sys.argv[1]
        logging_conf_file = sys.argv[2]

    conf = load_yaml(conf_file)

    test_app = load_app(conf_file, logging_conf_file)
    test_app.run(**conf['app_serve'])
